import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [ //定义多个一级路由
  {
    path: '/index',
    name: 'index',
    component: () => import('../views/Index.vue'),
    children:[ //嵌套路由( 二级路由 )  children 是内置的属性
      {
        path: '/index/first',
        name: 'first',
        component: () => import('../views/index/First.vue'),
      },
      {
        path: '/index/baobaotuan',
        name: 'baobaotuan',
        component: () => import('../views/index/BaoBaoTuan.vue')
      },
       {
        path: '/index/detail',
        name: 'detail',
        component: () => import('../views/index/Detail.vue')
      },
      {
        path: '/index/mine',
        name: 'mine',
        component: () => import('../views/index/Mine.vue')
      },
      //二级路由的重定向
      {
        path:'/index',
        redirect:'/index/first' 
      },
      //404路由
      {
        path:'*',
        component: () => import('../views/NotFound.vue') 
      }
    ]
  },
  //一级路由重定向
  {
    path:'/',
    redirect:'/index'  
  },
  //一级 404路由
  {
    path:'*',
    component: () => import('../views/NotFound.vue') 
  }
]

const router = new VueRouter({
  mode: 'history', //设置路由模式, history , hash
  base: process.env.BASE_URL,
  routes
})

export default router
